import { db } from './connect'
function findAll(sql: string, params = {}) {
  return db().prepare(sql).all(params)
}
function findOne(sql: string, params = {}) {
  return db().prepare(sql).get(params)
}
function insert(sql: string, params = {}) {
  return db().prepare(sql).run(params).lastInsertRowid
}
function update(sql: string, params: Record<string, any>) {
  return db().prepare(sql).run(params).changes
}
function del(sql: string, params = {}) {
  return db().prepare(sql).run(params).changes
}
function config() {
  const res = findOne(`select * from config where id = 1`) as { content: string }
  return JSON.parse(res.content)
}
export { findAll, findOne, insert, update, del, config }
